import java.util.Scanner;

class Process {
    String name;
    int[] claim;
    int[] allocation;
    int[] request;

    public Process(String name, int[] claim, int[] allocation, int[] request) {
        this.name = name;
        this.claim = claim;
        this.allocation = allocation;
        this.request = request;
    }
}

public class DeadlockDetection {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] available = new int[3];
        for (int i = 0; i < 3; i++) {
            available[i] = scanner.nextInt();
        }

        Process[] processes = new Process[5];
        for (int i = 0; i < 5; i++) {
            String name = scanner.next();
            int[] claim = new int[3];
            int[] allocation = new int[3];
            for (int j = 0; j < 3; j++) {
                claim[j] = scanner.nextInt();
                allocation[j] = scanner.nextInt();
            }
            processes[i] = new Process(name, claim, allocation, new int[3]);
        }

        String processName = scanner.next();
        int[] request = new int[3];
        for (int i = 0; i < 3; i++) {
            request[i] = scanner.nextInt();
        }
        Process targetProcess = null;
        for (Process process : processes) {
            if (process.name.equals(processName)) {
                targetProcess = process;
                break;
            }
        }

        boolean result = checkResourceAvailability(available, processes, targetProcess, request);
        System.out.println(result);
    }

    public static boolean checkResourceAvailability(int[] available, Process[] processes, Process targetProcess, int[] request) {
        int[] work = available.clone();
        for (Process process : processes) {
            if (process != targetProcess) {
                for (int i = 0; i < 3; i++) {
                    work[i] += process.allocation[i];
                }
            }
        }

        for (int i = 0; i < 3; i++) {
            if (request[i] > work[i]) {
                return false;
            }
        }

        for (int i = 0; i < 3; i++) {
            work[i] -= request[i];
        }

        for (Process process : processes) {
            if (process != targetProcess) {
                for (int i = 0; i < 3; i++) {
                    work[i] += process.allocation[i];
                }
            }
        }

        for (int i = 0; i < 5; i++) {
            if (work[i] < available[i]) {
                return false;
            }
        }

        return true;
    }
}
